package com.huabo.audit.exception;

import com.huabo.audit.util.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
* @description  异常处理器
* @author   lyz
* @date 2022/4/14 10:58
*/
@Slf4j
@RestControllerAdvice
public class CommercialExceptionHandler {


    @ExceptionHandler(Exception.class)
    @Order(Ordered.LOWEST_PRECEDENCE)
    public R handleException(Exception e) {
        log.error(e.getMessage(), e);
        return R.fail(e.getMessage());
    }
    /**
     * 处理自定义异常
     */
    @ExceptionHandler(CommercialException.class)
    public R handleMedicineException(CommercialException e) {
        log.error(e.getMessage(), e);
        return R.fail(e.getErrorCode(), e.getMessage());
    }

}
